//
//  SliderDemo.m
//  Exercise
//
//  Created by zhouxiaobo on 15/11/12.
//  Copyright © 2015年 mapath. All rights reserved.
//

#import "SliderDemo.h"

@implementation SliderDemo

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(screenWidth/2-150, 300, 300, 20)];
    slider.minimumValue = 0;
    slider.maximumValue = 10;
    slider.value = 0;
    [self.view addSubview:slider];
    
    //设置滑动动画
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(slideChange:) userInfo:slider repeats:NO];
    
    //滑动时触发
    [slider addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];
    
    //滑动到位置触发
    [slider addTarget:self action:@selector(changeLocationValue:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)slideChange:(NSTimer *)timer {
    UISlider *slider = [timer userInfo];
    [slider setValue:10 animated:YES];
}

- (void)changeValue:(UISlider *)slider {
    NSLog(@"%.2f",slider.value);
}

- (void)changeLocationValue:(UISlider *)slider {
    NSLog(@"滑动到了%.2f",slider.value);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
